package com.alibaba.web.controller;

import com.alibaba.api.pojos.Account;
import com.alibaba.web.config.NoToken;
import com.alibaba.web.dtos.RequestDTO;
import com.alibaba.web.dtos.ResponseResult;
import com.alibaba.web.service.WebService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/web")
public class WebController {

    @Autowired
    private WebService webService;

    @NoToken
    @PostMapping("/register")
    public ResponseEntity<ResponseResult> register(@RequestBody RequestDTO requestDTO) {
        return ResponseEntity.ok(webService.register(requestDTO));
    }

    @NoToken
    @GetMapping("/login")
    public ResponseEntity<ResponseResult> login(String phone, String code) {
        return ResponseEntity.ok(webService.login(phone, code));
    }

    @NoToken
    @GetMapping("/code")
    public ResponseEntity<ResponseResult> code(String phone) {
        return ResponseEntity.ok(webService.code(phone));
    }

    @GetMapping("/recharge")
    public ResponseEntity<ResponseResult> recharge(Double money) {
        return ResponseEntity.ok(webService.recharge(money));
    }

    @GetMapping("/withdrawal")
    public ResponseEntity<ResponseResult> withdrawal(Double money) {
        return ResponseEntity.ok(webService.withdrawal(money));
    }

    @GetMapping("/findByAccountId")
    public ResponseEntity<ResponseResult> findByAccountId() {
        return ResponseEntity.ok(webService.findByAccountId());
    }

    @GetMapping("/tradeList")
    public ResponseEntity<ResponseResult> tradeList() {
        return ResponseEntity.ok(webService.tradeList());
    }

    @PostMapping("/register/account")
    public ResponseEntity<ResponseResult> account(@RequestBody Account account) {
        return ResponseEntity.ok(webService.account(account));
    }
}
